package com.customization.shunsheng;

import com.engine.core.cfg.annotation.CommandDynamicProxy;
import com.engine.core.interceptor.AbstractCommandProxy;
import com.engine.core.interceptor.Command;
import com.engine.kq.cmd.leaverules.EditLeaveRulesCmd;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;

import java.util.Map;

/**
 * 修改假期规则的是否入职日期折算
 */
@CommandDynamicProxy(target = EditLeaveRulesCmd.class)
public class EditLeaveRulesCmdIntercept extends AbstractCommandProxy<Map<String,Object>> {

    @Override
    public Map<String, Object> execute(Command<Map<String, Object>> command) {
        BaseBean basebean = new BaseBean();
        basebean.writeLog("--------EditLeaveRulesCmdIntercept start to do--------");

        EditLeaveRulesCmd cmd = (EditLeaveRulesCmd) command;
        Map<String, Object> params = cmd.getParams();
        Map<String, Object> result = nextExecute(cmd);

        RecordSet rs=new RecordSet();

        String entryDiscount = Util.null2String(params.get("entryDiscount"));
        basebean.writeLog("EditLeaveRulesCmdIntercept entryDiscount: " + entryDiscount);

        String isSixYear = Util.null2String(params.get("isSixYear"));
        basebean.writeLog("EditLeaveRulesCmdIntercept isSixYear: " + isSixYear);

        String isDayCon = Util.null2String(params.get("isDayCon"));
        basebean.writeLog("EditLeaveRulesCmdIntercept isDayCon: " + isDayCon);

        String scaleDecimalDigit = Util.null2String(params.get("scaleDecimalDigit"));
        basebean.writeLog("EditLeaveRulesCmdIntercept scaleDecimalDigit: " + scaleDecimalDigit);

        String transferNumber = Util.null2String(params.get("transferNumber"));
        basebean.writeLog("EditLeaveRulesCmdIntercept transferNumber: " + transferNumber);

        String ruleId = Util.null2String(params.get("ruleId"));
        basebean.writeLog("EditLeaveRulesCmdIntercept ruleId: " + ruleId);

        String sign = Util.null2String(result.get("sign"));
        basebean.writeLog("EditLeaveRulesCmdIntercept sign: " + sign);

        if ("1".equals(sign)) {//原方法执行返回成功
            String syncEntryDisSql = "update kq_leaverulesdetail set isEntryDis = ? where id = ? ";
            if ("1".equals(entryDiscount)) {//是否入职日期折算--是
                boolean flag = rs.executeUpdate(syncEntryDisSql, 1, ruleId);
                basebean.writeLog("EditLeaveRulesCmdIntercept flag: " + flag);
            } else {
                boolean flag = rs.executeUpdate(syncEntryDisSql, 0, ruleId);
                basebean.writeLog("EditLeaveRulesCmdIntercept flag: " + flag);
            }

            String syncSixYearSql = "update kq_leaverulesdetail set isSixYear = ? where id = ? ";
            if ("1".equals(isSixYear)) {
                boolean flag = rs.executeUpdate(syncSixYearSql, 1, ruleId);
                basebean.writeLog("EditLeaveRulesCmdIntercept flag: " + flag);
            } else {
                boolean flag = rs.executeUpdate(syncSixYearSql, 0, ruleId);
                basebean.writeLog("EditLeaveRulesCmdIntercept flag: " + flag);
            }

            String syncDayConSql = "update kq_leaverulesdetail set isDayCon = ? where id = ? ";
            if ("1".equals(isDayCon)) {
                boolean flag = rs.executeUpdate(syncDayConSql, 1, ruleId);
                basebean.writeLog("EditLeaveRulesCmdIntercept flag: " + flag);
            } else {
                boolean flag = rs.executeUpdate(syncDayConSql, 0, ruleId);
                basebean.writeLog("EditLeaveRulesCmdIntercept flag: " + flag);
            }

            String syncscaleSql = "update kq_leaverulesdetail set scaleDecimalDigit = ? where id = ? ";
            boolean flag = rs.executeUpdate(syncscaleSql, scaleDecimalDigit, ruleId);
            basebean.writeLog("scaleDecimalDigit flag: " + flag);

            String syncTransferNumberSql = "update kq_leaverulesdetail set transferNumber = ? where id = ? ";
            flag = rs.executeUpdate(syncTransferNumberSql, transferNumber, ruleId);
            basebean.writeLog("transferNumber flag: " + flag);
        }


        return result;
    }

}
